﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
using CommunitySystem.Elements;
using CommunitySystem.Assert;
using CommunitySystem;
using CommunitySystem.Map;
using EHR.Common;
using CommunitySystem.Views;

namespace CommunitySystem
{
    public partial class PageIndex : AsyncCtrl
    {
        private DataService.MenuItem _menu;
    
        public PageIndex(DataService.MenuItem mode)
        {
            InitializeComponent();
            _menu = mode;
            InitModel();
        }

        private void InitModel()
        {
            Worker.IsBusy = true;
            try
            {
                object obj = Activator.CreateInstance(Type.GetType(_menu.Target), new object[] { _menu.ID, xBusy });
                obj.GetType().GetProperty("Nav").SetValue(obj, new NavMoveSwitch() { FirstPage = obj as FrameworkElement }, null);
                flipSwitch.SetNewPage(obj as CommunitySystem.Views.IAsyncCtrl, obj.GetType().GetProperty("Nav").GetValue(obj, null) as NavMoveSwitch);
            }
            catch (Exception ex)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("导航地址不正确！");
                xBusy.IsBusy = false;
            }
            Worker.IsBusy = false;
        }
    }
}
